package achievementrequest

import (
	"strings"

	"github.com/gin-gonic/gin"
	"lab.com/define/errorcode"
	"lab.com/request"
)

// AchievementListInputParams 科研成果列表查询参数
type AchievementListInputParams struct {
	Title  string `json:"title" form:"title" comment:"关键字"`
	Type   int    `json:"type" form:"type" validate:"oneof=0 10 20 30 40 50" comment:"科研成果类型"`
	IsHome int    `json:"is_home" form:"is_home" validate:"oneof=0 10" comment:"是否是首页列表，10是，0不是"`
	request.PageOffset
}

// AchievementInfo 科研成果列表信息
type AchievementInfo struct {
	Id         int    `json:"id"`
	Title      string `json:"Title"`
	Abstract   string `json:"abstract"`
	Type       int    `json:"type"`
	TypeDesc   string `json:"type_desc"`
	UpdateTime string `json:"update_time"`
	Weight     int    `json:"weight"`
}

// AchievementListRes 科研成果列表返回结果
type AchievementListRes struct {
	List  []AchievementInfo `json:"list"`
	Count int               `json:"count"`
}

// CheckInputParams return input params
func (achievement *AchievementListInputParams) CheckInputParams(c *gin.Context) error {

	if err := c.ShouldBind(achievement); err != nil {
		return err
	}
	if errs, err := request.Validate(achievement); err != nil {
		return errorcode.New(errorcode.ErrParams, strings.Join(errs, ","), nil)
	}

	achievement.ParseOffset()
	return nil
}
